package subject_set.offer100;

import java.util.Deque;
import java.util.LinkedList;

/**
 * @author haomin
 * @date 2022/10/22 18:33
 **/
public class Offer54 {
    class Solution {
        public int kthLargest(TreeNode root, int k) {
            Deque<TreeNode> s = new LinkedList<>();
            while(root != null || !s.isEmpty()){
                while(root != null){
                    s.push(root);
                    root = root.right;
                }
                root = s.pop();
                if(--k == 0) return root.val;
                root = root.left;
            }
            return 0;
        }
    }
}